﻿@model IEnumerable<MyPS.Areas.Manage.Models.RoleAuthorModel>
<table class="tableBorder">
    <tr>
        <th colspan="8">@ViewBag.RoleID
        </th>
    </tr>
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.ResourceID)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.ResourceName)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Mode)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.IS_View)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.IS_Add)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.IS_Edit)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.IS_Del)
        </th>
        <th>
        </th>
    </tr>
    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.ResourceID)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.ResourceName)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Mode)
            </td>
            <td class="isview">
                @if (item.IS_View == "Y")
                { 
                    <input type="checkbox" checked />
                }
                else
                { 
                    <input type="checkbox" /> 
                }
            </td>
            <td clsaa="isadd">
                @if (item.IS_Add == "Y")
                { 
                    <input type="checkbox" checked />
                }
                else
                { 
                    <input type="checkbox" /> 
                }
            </td>
            <td class="isedit">
                @if (item.IS_Edit == "Y")
                { 
                    <input type="checkbox" checked />
                }
                else
                { 
                    <input type="checkbox" /> 
                }
            </td>
            <td clsas="isdel">
                @if (item.IS_Del == "Y")
                { 
                    <input type="checkbox" checked />
                }
                else
                { 
                    <input type="checkbox" /> 
                }
            </td>
            <td>
                <input data-resourceid="@item.ResourceID" type="button" class="btnAuthorEdit" value="提交" />
            </td>
        </tr>
    }
</table>
<script type="text/javascript">
    $(document).ready(function () {
        $(".btnAuthorEdit").click(function () {
            var roleid = "@ViewBag.RoleID";
            var resourceid = $(this).attr("data-resourceid");
            var isview = $(this).parent().prevAll().eq(3).children().attr("checked") == "checked" ? "Y" : "N";
            var isadd = $(this).parent().prevAll().eq(2).children().attr("checked") == "checked" ? "Y" : "N";
            var isedit = $(this).parent().prevAll().eq(1).children().attr("checked") == "checked" ? "Y" : "N";
            var isdel = $(this).parent().prevAll().eq(0).children().attr("checked") == "checked" ? "Y" : "N";
            $.post("/Ajax/AddRoleResource", { RoleID: roleid, ResourceID: resourceid, IS_View: isview, IS_Add: isadd, IS_Edit: isedit, IS_Del: isdel, random: Math.random() }, function (r) {
                alert(r);
            }
            )
        });
    });
</script>
